package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ExtHelper;
import com.ruoyi.common.utils.uuid.IdGeneratorSnowflake;
import com.ruoyi.system.domain.PracticeCadetAttendance;
import com.ruoyi.system.domain.PracticeCadetAttendanceReport;
import com.ruoyi.system.mapper.PracticeCadetAttendanceMapper;
import com.ruoyi.system.service.IPracticeCadetAttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 实践考勤Service业务层处理
 *
 * @author dp
 * @date 2023-11-27
 */
@Service
public class PracticeCadetAttendanceServiceImpl implements IPracticeCadetAttendanceService {
    @Autowired
    private PracticeCadetAttendanceMapper practiceCadetAttendanceMapper;
    @Autowired
    IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询实践考勤
     *
     * @param attendanceId 实践考勤主键
     * @return 实践考勤
     */
    @Override
    public PracticeCadetAttendance selectPracticeCadetAttendanceByAttendanceId(Long attendanceId) {
        return practiceCadetAttendanceMapper.selectPracticeCadetAttendanceByAttendanceId(attendanceId);
    }

    /**
     * 查询实践考勤列表
     *
     * @param practiceCadetAttendance 实践考勤
     * @return 实践考勤
     */
    @Override
    public List<PracticeCadetAttendance> selectPracticeCadetAttendanceList(PracticeCadetAttendance practiceCadetAttendance) {
        return practiceCadetAttendanceMapper.selectPracticeCadetAttendanceList(practiceCadetAttendance);
    }

    /**
     * 查询实践考勤报表
     *
     * @param practiceCadetAttendance 实践考勤
     * @return 实践考勤
     */
    @Override
    public List<PracticeCadetAttendanceReport> selectPracticeCadetAttendanceReport(PracticeCadetAttendanceReport practiceCadetAttendance) {
        return practiceCadetAttendanceMapper.selectPracticeCadetAttendanceReport(practiceCadetAttendance);
    }

    /**
     * 新增实践考勤
     *
     * @param practiceCadetAttendance 实践考勤
     * @return 结果
     */
    @Override
    public int insertPracticeCadetAttendance(PracticeCadetAttendance practiceCadetAttendance) {
        practiceCadetAttendance.setCreateTime(DateUtils.getNowDate());
        return practiceCadetAttendanceMapper.insertPracticeCadetAttendance(practiceCadetAttendance);
    }

    /**
     * 修改实践考勤
     *
     * @param practiceCadetAttendance 实践考勤
     * @return 结果
     */
    @Override
    public int updatePracticeCadetAttendance(PracticeCadetAttendance practiceCadetAttendance) {
        return practiceCadetAttendanceMapper.updatePracticeCadetAttendance(practiceCadetAttendance);
    }

    /**
     * 批量删除实践考勤
     *
     * @param attendanceIds 需要删除的实践考勤主键
     * @return 结果
     */
    @Override
    public int deletePracticeCadetAttendanceByAttendanceIds(Long[] attendanceIds) {
        return practiceCadetAttendanceMapper.deletePracticeCadetAttendanceByAttendanceIds(attendanceIds);
    }

    /**
     * 删除实践考勤信息
     *
     * @param attendanceId 实践考勤主键
     * @return 结果
     */
    @Override
    public int deletePracticeCadetAttendanceByAttendanceId(Long attendanceId) {
        return practiceCadetAttendanceMapper.deletePracticeCadetAttendanceByAttendanceId(attendanceId);
    }

    /**
     * 实体数据补全
     *
     * @param practiceCadetAttendance 实体
     * @param userId                  用户id
     * @param crateType               创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(PracticeCadetAttendance practiceCadetAttendance, Long userId, Integer crateType) {
        //主键
        if (practiceCadetAttendance.getAttendanceId() == null || "".equals(practiceCadetAttendance.getAttendanceId())) {
            practiceCadetAttendance.setAttendanceId(ExtHelper.toString(idGeneratorSnowflake.nextId()));
        }
        //创建人、创建时间
        if (crateType == 1) {
            if (practiceCadetAttendance.getCreateBy() == null) {
                practiceCadetAttendance.setCreateBy(userId.toString());
            }
            if (practiceCadetAttendance.getCreateTime() == null) {
                practiceCadetAttendance.setCreateTime(DateUtils.getNowDate());
            }
        }
        //修改人
        if (practiceCadetAttendance.getModifyBy() == null) {
            practiceCadetAttendance.setModifyBy(userId);
        }
        //修改时间
        if (practiceCadetAttendance.getModifyTime() == null) {
            practiceCadetAttendance.setModifyTime(DateUtils.getNowDate());
        }
    }
}
